package com.scqzy.shengchunqiang.sword2offer.day23;

/**
 * @Description: 剑指 Offer 66. 构建乘积数组
 * @Author 盛春强
 * @Date 2021/8/30 19:13
 */
public class ConstructArr {
    public int[] constructArr(int[] a) {
        int[] res = new int[a.length];
        for (int i = 0, tmp = 1; i < a.length; i++) {
            res[i] = tmp;
            tmp *= a[i];
        }
        for (int i = a.length - 1, tmp = 1; i >= 0; i--) {
            res[i] *= tmp;
            tmp *= a[i];
        }
        return res;
    }
}
